
import Head from 'next/head'

<Head>
  <script>
    {
      `(function() {
         var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e60fb290e204e04c5cb6f79b0ac1e697";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
       })();`
    }
  </script>
</Head>

![LangChain](https://pica.zhimg.com/50/v2-56e8bbb52aa271012541c1fe1ceb11a2_r.gif)






QA生成 QA Generation
 [#](#qa-generation "Permalink to this headline")
=================================================================




这个教程展示了如何使用`QAGenerationChain`来对特定文档提出问题-答案对。

这一点很重要, 因为很多时候你可能没有数据来评估你的问答系统，所以这是一种廉价而轻量级的方法来生成它！






```python
from langchain.document_loaders import TextLoader

```










```python
loader = TextLoader("../../modules/state_of_the_union.txt")

```










```python
doc = loader.load()[0]

```










```python
from langchain.chat_models import ChatOpenAI
from langchain.chains import QAGenerationChain
chain = QAGenerationChain.from_llm(ChatOpenAI(temperature = 0))

```










```python
qa = chain.run(doc.page_content)

```










```python
qa[1]

```








```python
{'question': 'What is the U.S. Department of Justice doing to combat the crimes of Russian oligarchs?',
 'answer': 'The U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs.'}

```







